package login

import (
	"context"
	v1 "donkey-admin/api/menu/v1"
	"donkey-admin/internal/dao"
	"donkey-admin/internal/model/do"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/google/uuid"
)

func (s *sAuthMenu) AuthMenuAdd(ctx context.Context, req *v1.MenuAddReq) (res *v1.MenuAddRes, err error) {

	uuidString := uuid.New().String()

	_, err = dao.SysMenu.Ctx(ctx).Insert(&do.SysMenu{
		Uuid:          uuidString,
		MenuName:      req.MenuName,
		MenuPath:      req.MenuPath,
		MenuTitle:     req.MenuTitle,
		MenuIcon:      req.MenuIcon,
		MenuType:      req.MenuType,
		MenuAffix:     req.MenuAffix,
		MenuTag:       req.MenuTag,
		MenuComponent: req.MenuComponent,
		MenuParentId:  req.MenuParentId,
		MenuHidden:    req.MenuHidden,
		MenuOrder:     req.MenuOrder,
		MenuFullpage:  req.MenuFullpage,
		MenuRedirect:  req.MenuRedirect,
	})
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, err
	}

	return &v1.MenuAddRes{Uuid: uuidString}, nil
}
